package com.woniuxy.project115.kaer.platform.controller;


import com.woniuxy.project115.kaer.commons.util.Result;
import com.woniuxy.project115.kaer.platform.annotation.RequirePermission;
import com.woniuxy.project115.kaer.platform.annotation.RequireRole;
import com.woniuxy.project115.kaer.platform.entity.Permission;
import com.woniuxy.project115.kaer.platform.service.PermissionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author fyy
 * @since 2025年02月23日
 */
@RestController
@RequestMapping("/permission")
@Api(tags = "权限资源管理")
public class PermissionController {
    @Resource
    private PermissionService permissionService;

    //查看所有权限资源
    @GetMapping("/getAllPermission")
    @ApiOperation("查看所有权限资源")
    @RequireRole("超级管理员")
    @RequirePermission("获取所有权限资源")
    public Result getAllPermission() throws Exception {
        final List<Permission> allPermission = permissionService.getAllPermission();
        return Result.succeed("获取所有权限成功",allPermission);
    }

    //递归查询所有子权限
    @GetMapping("/getAllChildPermission")
    @ApiOperation("递归查询所有子权限")
    @RequireRole("超级管理员")
    @RequirePermission("递归查询所有资源")
    public Result getAllChildPermission() throws Exception {
        return Result.succeed("获取所有子权限成功",permissionService.getAllChildPermission());
    }

}

